<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产品管理</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
</head>
<body>
<div class="dashboard-container" id="product-app">
    <div class="container">
        <div class="tableBar">
            <div class="tableLab">
                <div class="demo-input-suffix">
                    产品名称: <el-input v-model="conditions.name" placeolder="输入产品名称" style="width: 250px" clearable ></el-input>
                    用户名: <el-input v-model="conditions.username" placeolder="输入用户名" style="width: 250px" clearable ></el-input>
                </div>
                <div class="demo-input-suffix">
                    产品标识: <el-input v-model="conditions.productKey" placeolder="输入产品标识Key" style="width: 250px" clearable></el-input>
                    行政区: <el-select v-model="conditions.areaCode" placeholder="选择行政区">
                        <el-option
                                v-for="item in areaList"
                                :key="item.code"
                                :label="item.name"
                                :value="item.code">
                        </el-option>
                    </el-select>
                    <el-button  type="primary" icon="el-icon-search" @click="handleQuery()">搜索</el-button>
                </div>
            </div>
        </div>
        <el-table  :data="pagination.tableData"  stripe  class="tableBox" >
            <el-table-column type="index" width="50" label="序号"></el-table-column>
            <el-table-column  prop="name" label="产品名称"  /></el-table-column>
            <el-table-column prop="tenantId"  label="所属租户" >
                <template slot-scope="scope">
                    <span v-for="item in tenantList" v-if="scope.row.tenantId==item.id">
                        <el-tag type="warning">{{item.name}}</el-tag>
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="areaCode"  label="行政区" >
                <template slot-scope="scope">
                    <span v-for="item in areaList" v-if="scope.row.areaCode==item.code">
                        <el-tag type="success">{{item.name}}</el-tag>
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="username"  label="用户名" width="280"></el-table-column>
            <el-table-column prop="productKey"  label="产品标识Key" width="280"></el-table-column>
        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pagination.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pagination.counts"
                @size-change="handleSizeChange"
                :current-page.sync="pagination.page"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
</div>
<script src="../../plugins/vue/vue.js"></script>
<script src="../../plugins/element-ui/index.js"></script>
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/product.js"></script>
<script type="text/javascript">
    new Vue({
        el: '#product-app',
        data() {
            return {
                action: '',
                type: '',
                pagination: {
                    tableData: [],
                    page: 1,
                    pageSize: 10,
                    counts:0,
                },
                conditions:{
                    name:'',
                    username:'',
                    areaCode:'',
                    productKey:''
                },
                tenantList:[],
                areaList:[]
            }
        },
        methods: {
            async init() {
                const params = {
                    page: {
                        current: this.pagination.page,//当前页码
                        size: this.pagination.pageSize,//每页大小
                    },
                    name: this.conditions.name ? this.conditions.name : undefined,
                    username: this.conditions.username ? this.conditions.username : undefined,
                    areaCode: this.conditions.areaCode ? this.conditions.areaCode : undefined,
                    productKey: this.conditions.productKey ? this.conditions.productKey : undefined
                };
                await findProductPage(params).then(res => {
                    if (String(res.code) === '200') {
                        this.pagination.tableData = res.data.records;
                        this.pagination.counts = res.data.total;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 关闭弹窗
            handleClose(st) {
                this.classData.dialogVisible = false
            },


            //查询所有行政区
            async initAreaList(){
                await findAreaAll().then(res => {
                    if (String(res.code) === '200') {
                        this.areaList = res.data;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                });
            },
            //查询所有租户
            async initTenantList(){
                await findTenantAll().then(res => {
                    if (String(res.code) === '200') {
                        this.tenantList = res.data;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                });
            },
            //分页相关全部操作
            handleSelectionChange(val) {
                let checkArr = []
                val.forEach((n) => {
                    checkArr.push(n.id)
                })
                this.checkList = checkArr
            },
            handleSizeChange(val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange(val) {
                this.page = val
                this.init()
            },
        },
        created() {
            this.init();
            this.initTenantList();
            this.initAreaList();
        }
    })
</script>
</body>
</html>